package com.yunze.web.controller.yunze.install;

import com.alibaba.fastjson.JSON;
import com.yunze.common.utils.ServletUtils;
import com.yunze.common.utils.ip.IpUtils;
import com.yunze.common.utils.yunze.AesEncryptUtil;
import com.yunze.system.service.yunze.install.YzInstallPlacefloorService;
import com.yunze.web.core.config.MyBaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 按警联系人操作
 * @author liuhang
 * @date 2022-6-10
 * */

@Api("楼层管理")
@RestController
@RequestMapping("/yunze/placefloor")
public class YzInstallPlacefloorController extends MyBaseController {

    @Autowired
    private YzInstallPlacefloorService yzInstallPlacefloorService;


    /**
     * 执行 楼层管理 列表
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placefloor:list')")
    @PostMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
    public String SynFlow(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallPlacefloorService.PstrMap(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placefloor:list  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("楼层管理[列表] 操作失败！");
    }

    /**
     * 查询建筑物名称
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placefloor:libigst')")
    @PostMapping(value = "/libigst", produces = {"application/json;charset=UTF-8"})
    public String buildingName() {
        try {
            return MyRetunSuccess(yzInstallPlacefloorService.libigst(), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placefloor:libigst  <br/> Pstr = " + ip + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("查询建筑物名称 操作失败！");
    }

    /**
     * 执行 楼层管理 新增
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placefloor:add')")
    @PostMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public String Add(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacefloorService.add(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("新增 楼层管理 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placefloor:add  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("楼层管理[新增] 操作失败！");
    }


    /**
     * 执行 楼层管理 修改
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placefloor:upd')")
    @PostMapping(value = "/upd", produces = {"application/json;charset=UTF-8"})
    public String Upd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacefloorService.upd(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("修改 楼层管理 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placefloor:upd  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("楼层管理[修改] 操作失败！");
    }


    /**
     * 删除
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placefloor:del')")
    @PostMapping(value = "/del", produces = {"application/json;charset=UTF-8"})
    public String Del(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacefloorService.del(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("删除 楼层管理 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placefloor:del  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("楼层管理[删除] 操作失败！");
    }


    /**
     * 查询楼层
     * @param Pstr
     * @return
     */
    @PreAuthorize("@ss.hasPermi('yunze:placefloor:floor')")
    @PostMapping(value = "/floor", produces = {"application/json;charset=UTF-8"})
    public String FloorPlaceFloor(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacefloorService.floor(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("查询楼层 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placefloor:floor  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("查询楼层 操作失败！");
    }


}
